import  Express from 'express'

//express 返回一个函数，该函数返回一个app 对象

export class Server{
    app:Express.Application
    constructor(){
        this.app=Express()
    }
    // express 默认配置
    private defaultConfig():void{

    }

    use(fn:any){
        this.app.use(fn)
    }

    run(port?:number,address?:string,callback?:()=>void){
        if(!port){
            port=8090
        }
        if(!address){
            address="127.0.0.1"
        }
        if(!callback){
            callback=function(){
                console.log(`server started at ${port}`)
            }
        }
        // server 运行
       return this.app.listen(port,address,callback)
    }
}